<?php
/*
	提现
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
global $_RQ;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
$merchid=$this->model('merch')->checklogin();
if($_RQ['op']=='get'){
	$minmoney=$this->setting['minmoney']?:1;
	$cashdays=$this->setting['cash_day']?:1;
	$cashtime = mktime(0,0,0,date('m'),date('d')-$cashdays,date('Y'));
	$return['yesget_money']=pdo_getsum('jy_liangoods_sendlog',array('clearstatus'=>0,'uniacid'=>$_SESSION['uniacid'],'merchid'=>$merchid,'status'=>4),'price');
	$return['yesget_money']=intval($return['yesget_money']);
	if($return['yesget_money']<$minmoney){
		exi('不能提现，可提现金额不能小于'.$minmoney.'元','','/merch.index/');
	}
	$charges=intval($this->setting['peisong_rate'])*$return['yesget_money']/100;
	$return['get_price']=$return['yesget_money']-$charges;
	$setting['type_array']=array('提现到微信钱包','提现到支付宝','提现到银行卡');
	$return['post']['type']='0';
	$return['post']['yesget_money']=$return['yesget_money'];
	$return['pay_types']=$this->pay_types;
	exi($return);
}
if($_RQ['op']=='post'){
	$post=get_postdata();
	$fee=intval($post['yesget_money']);
	$charges=intval($this->setting['peisong_rate'])*$fee/100;
	if($post['pay_type']=='alipay'){
			if(!$post['realname']){
				exi('请先填写真实姓名！','error');
			}
			if(!$post['alipay']){
				exi('请先填写支付宝帐号！','error');
			}
			if(!$post['alipay1']){
				exi('请确认帐号','error');
			}
			if($post['alipay1']!=$post['alipay']){
				exi('确认帐号与支付宝帐号不匹配！','error');
			}
			$typetitle='支付宝';
		}
		if($post['pay_type']=='union'){
			if(!$post['realname']){
				exi('请输入姓名','error');
			}
			if(!$post['bankname']){
				exi('请输入所属银行','error');
			}
			if(!$post['bankcard']){
				exi('请银行卡号','error');
			}
			if(!$post['bankcard1']){
				exi('请确认卡号','error');
			}
			if($post['bankcard']!=$post['bankcard1']){
				exi('确认卡号与银行卡号不匹配！','error');
			}
			$typetitle='银行卡';
	}
	$cash=array(
		'uniacid'=>$_SESSION['uniacid'],
		'balancesn'=>get_ordersn('jy_liangoods_balance','balancesn'),
		'merchid'=>$merchid,
		'money'=>$fee,
		'pay_type'=>intval($post['pay_type']),
		'balance_pay'=>$charges,
		'pay_type'=>$post['pay_type'],
		'pay_trade_no'=>$post['pay_trade_no'],
		'realname'=>$post['realname'],
		'alipay'=>$post['alipay'],
		'bankname'=>$post['bankname'],
		'bankcard'=>$post['bankcard'],
		'createtime'=>TIMESTAMP,
		'status'=>0,
	);
	$cash['final_money']=$cash['money']-$cash['balance_pay'];
	pdo_insert('jy_liangoods_balance',$cash);
	$id=pdo_insertid();
	$this->model('merch')->cash_sendlog($merchid);
	exi('申请提现成功，请等待管理员审核！','','/merch.index/');
}